import {CreateUserVo, UserInfo, UserLoginVo} from "@/api/Objects/UserTypes.ts";
import REQ from "@/api/Req.ts";
import {Res, RPage} from "@/api/Objects";

class UserApi {
    public getSelfInfo = async (): Promise<UserInfo> => {
        const res = await REQ<null, Res<UserInfo>>({
            method: "get",
            url: "/user/user"
        })
        return res.data
    }

    public logout = async (): Promise<Res<null>> => {
        return await REQ<any, Res<null>>({
            url: "/user/user/logout"
        })
    }

    public login = async (param: UserLoginVo) => {
        return await REQ<UserLoginVo, Res<null>>({
            method: "post",
            url: "/user/user/login",
            data: param
        })
    }

    public createUser = async (param: CreateUserVo) => {
        return await REQ<CreateUserVo, Res<null>>({
            method: "post",
            url: "/user/user/create",
            data: param
        })
    }

    public pageUser = async () => {
        return await REQ<null, Res<RPage<UserInfo>>>({
            method: "get",
            url: "/user/user/page",
            params: {
                current: 1,
                size: 10
            }
        })
    }

    public updateUser = async (data: UserInfo) => {
        return await REQ<UserInfo, Res<null>>({
            method: "post",
            url: "/user/user/update",
            data: data
        })
    }
}

export default new UserApi()